package com.lemeng.message;

import com.alibaba.fastjson.JSONObject;
import com.lemeng.pojo.OrderItem;
import com.lemeng.service.StockBackService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class MyMessageConsumer implements MessageListener {

    @Autowired
    StockBackService stockBackService;


    @Override
    public void onMessage(Message message) {

        String mapStr = new String(message.getBody());

        System.out.println("收到消息"+mapStr);
        List<OrderItem> orderItems = JSONObject.parseArray(mapStr, OrderItem.class);

        stockBackService.addBackInfo(orderItems);

        System.out.println("插入数据完成");

    }
}
